import { accountList } from '@/apilist/AccountList'

import { getStaffInfo } from "@/apilist/Staff";

const state = {
    account_list: {
        list: [],
        total: 0,
    },
    state_list: [],
    //员工详情
    staffInfo: {
        id: '',
        account: '',
        username: '',
        id_card: '',
        phone: '',
        email: '',
        position_id: '',
        deptid: '',
        status: '',
        address: '',
        avatar: '',
        dept_list: [],
        position_list: [],
        sex: 0,
        password: '',
        repeatPassword: '',
    },
}


const mutations = {
    //获取用户列表
    getAccountListMutations(state, data) {
        state.account_list.list = data.data
        state.account_list.total = data.total
        state.state_list = data.state_list
    },
    //获取员工详情
    getStaffInfoMutations(state, data) {
        let staff = data
            //console.log('11222',data)
        state.staffInfo.id = staff.id
        state.staffInfo.account = staff.account
        state.staffInfo.username = staff.username
        state.staffInfo.id_card = staff.id_card
        state.staffInfo.phone = staff.phone
        state.staffInfo.email = staff.email
        state.staffInfo.position_id = staff.position_id
        state.staffInfo.deptid = staff.deptid
        state.staffInfo.status = staff.status
        state.staffInfo.address = staff.address
        state.staffInfo.avatar = staff.avatar
        state.staffInfo.dept_list = staff.dept_list
        state.staffInfo.position_list = staff.position_list
        state.staffInfo.sex = staff.sex
        state.staffInfo.roleid = staff.roleid
    }
}


const actions = {
    //获取用户列表
    async getAccountListActions(ctx, data) {
        let res = await accountList(data)
        ctx.commit('getAccountListMutations', res.data)
    },
    //获取员工详情
    async getStaffInfoActions(ctx, data) {
        let res = await getStaffInfo(data)
        ctx.commit('getStaffInfoMutations', res.data)
    },
}



export default {
    namespaced: true,
    state,
    mutations,
    actions
}